package org.example.fronted.service.impl;


import org.example.entity.User;
import org.example.fronted.mapper.FrontedUserMapper;
import org.example.fronted.service.RegisterService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class RegisterServiceImpl implements RegisterService {

    private FrontedUserMapper userMapper;

    public RegisterServiceImpl(FrontedUserMapper userMapper){
        this.userMapper=userMapper;
    }

    @Override
    public boolean saveUser(User user) {


        user.setUBalance(BigDecimal.valueOf(9999.00));
        user.setURegisterDate(new Date());

        try {
            userMapper.saveUser(user);
            return true;
        }catch (Exception e){
            return false;
        }
    }


    @Override
    public boolean checkUser(String username) {
//        boolean isExist = UserCheckDao.checkUser(username);
        List<User> users = userMapper.selectUserByName(username);
        if (users.size()>0){
            return true;
        }
        return false;
    }
}
